package com.lhd.controller;

import com.lhd.mapper.RecordMapper;
import com.lhd.pojo.PageBean;
import com.lhd.pojo.PageCondition;
import com.lhd.pojo.Record;
import com.lhd.pojo.Result;
import com.lhd.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/record")
public class RecordController {
    @Autowired
    RecordService recordService;
    @PostMapping
    public Result add(@RequestBody Record record){
        recordService.add(record);
        return Result.success();
    }
    @GetMapping
    public Result getByUid(){
        List<Record> list = recordService.getByUid();
        return Result.success(list);
    }
    @GetMapping("/all")
    public Result getAll(){
        List<Record> records = recordService.getAll();
        return Result.success(records);
    }
    @GetMapping("/condition")
    public Result getWithCondition(String uname, String gname, String sname, PageCondition pageCondition){
        PageBean<Record> pageBean = recordService.getByCondition(uname,gname,sname,pageCondition);
        return Result.success(pageBean);
    }
    @PatchMapping("/state")
    public Result updateCredit(Integer state,Integer id){
        recordService.updateState(state,id);
        return Result.success();
    }
}
